<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html">
<html>
<head>
	<style type="text/css">
		.infodiv{
		 display:none;
		/* border:1px solid #000;
		display:block; */
		 width:550px;
		height:40px; 
		position: absolute;
		}
		.info,.update{
			margin-right:10px;
			color:blue;
			cursor: pointer;
		}
		#div_one table{
		margin-top:20px;
		 border:1px solid #000; 
		text-align:center;
		}
		#div_one table tr{
		height:30px;
		font-size:15px;
		}
		#div_one table tr td{
		width:95px;
		 border:1px solid #000; 
		}
		.border{
			border:1px solid #000;
		}
		label, .goodsid {
			vertical-align: middle;
		}
		
		.border2{
		border:0px;
		}
		input{
		border:0px;
		text-align:center;
		width:65px;
		background-color:#cfcfcf;
		}
		#ipage{
			color:#4f4f4f;
			width:20px;
			height:20px;
			display:inline-block;
			text-align:center;
			border-radius:2px;
			background-color:#E5E5E5;
			cursor: pointer;
		}
		#apage{
			color:#4f4f4f;
			width:20px;
			height:20px;
			display:inline-block;
			text-align:center;
			border-radius:2px;
			background-color:#EED8AE;
			cursor: pointer;
		}
		#tpage{
			color:#4f4f4f;
			width:40px;
			height:20px;
			display:inline-block;
			text-align:center;
			border-radius:2px;
			background-color:#EED8AE;
			cursor: pointer;
		}
		#dpage{
			color:#4f4f4f;
			width:50px;
			height:20px;
			display:inline-block;
			text-align:center;
			border-radius:2px;
			background-color:#EED8AE;
			cursor: pointer;
		}
		.update_content{
    width: 55px;
    line-height: 20px;
    height: 20px;
    color: white;
    cursor: pointer;
    float: right;
    margin-top: 3px;
    background-color: black;
    border: solid 1px red;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    text-align: center;
		}
		.info_content{
margin: 2px auto;
    cursor:pointer;
    width: 55px;
    line-height: 20px;
    height: 20px;
    float: left;
    color: white;
    background-color: black;
    border: solid 1px red;
		}
		.update_content_true{
		margin:0 auto;
		width: 55px;
		line-height:20px;
		height:20px;
		float:right;
		color:white;
		background-color:black;
		border: solid 2px red;
		cursor: pointer;
		}
		tr td .imgs {
		width: 17px;
		height:17px;
		}
		div p input {
	   border:solid 1px #000080;
	   width: 260px;
	   margin-top:4px;
	   height: 27px;
}
	</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

</head>
<body>
<div style="width: 100%" id="goods_list">
	<div style="width:1100px;margin: 0 auto;" id="div_one">
	<div>
		<h4 style="margin-left:20px;">商品列表</h4>
		<div style="width:800px;/*  border: solid 2px red; */">
			<p>商品编号：<input type="text" name="goodsid" id="goodsid"></p>
			<p>商品名称：<input type="text" name="goodsname" id="goodsname"></p>
			<p ><input style="margin-left: 80px; width: 100px;background-color: #000;color: #fff;cursor: pointer;" id="select" type="button" value="查询"></p>
		</div>
		 
		</div>
	<table cellpadding="0" cellspacing="0"  style="border-collapse:collapse;">
		<tr style="font-weight: bold;">
			<td>商品ID</td>
<!--  			<td>分类ID</td>
			<td>类型ID</td>
			<td>品牌ID</td>  -->
			<td style="width: 210px;">商品名称</td>
			<td>商品货号</td>
  			<td>市场售价</td>
		<!-- 	<td>报警数量</td> -
		    <td>简短描述</td>
			<td>购买积分</td>
			<td>添加时间</td>
			<td>是否删除</td> -->
			<td>是否新品</td>
			<td>是否热销</td>
			<td>是否删除</td>
			<td>库存数量</td> 
			<td>额外积分</td> 
			<td style="width: 130px;">商品操作</td>
		</tr>
		<c:forEach items="${pageBean}" var="list">
			<tr >
				<td><input  style="width: 30px;" class="goodsid" type="radio" value="${list.goodsid}" /><label style="line-height: 15px;" >${list.goodsid}</label></td>
<%-- 				<td><input id="" type="text" value="${list.catid }" /></td>
				<td><input id="" type="text" value="${list.typeid}" /></td>
				<td><input id="" type="text" value="${list.brandid}" /></td>  --%>
				<td><input  style="width: 210px;" class="goodsname" type="text" value="${list.keywords}" /></td>
				<td><input class="goodssn" type="text" value="${list.goodssn}" /></td>
				<td><input  class="marketprice" type="number" value="${list.marketprice}" /></td>
<%-- 			<td><input id="" type="text" value="${list.warnnumber }" /></td>
				<td><input id="" type="text" value="${list.goodsbrief}" /></td>
				<td><input id="" type="text" value="${list.integral}" /></td>
				<td><input id="" type="text" value="${list.addtime}" /></td>
				<td><input id="" type="text" value="${list.isdelete}" /></td> --%>
				<td><input class="imgs"  id="isnew" value="${list.isnew }" type="image" src="${list.isnew }" /></td>
				<td><input class="imgs"   id="ishot" value="${list.ishot }" type="image" src="${list.ishot }" /></td>
				<td><input  class="imgs"  id="isdelete" value="${list.goodsid }" type="image" src="${list.isdelete }" /></td>
				<td><input  class="goodsnumber" type="text" value="${list.goodsnumber}" /></td> 
				<td><input id="do_goods" class="giveintegral" type="text" value="${list.giveintegral}" /></td> 
				<td><div class="info_content" id="${list.goodsid}">详情</div>
				<div id="${list.goodsid}" class="update_content" >修改</div>
				<div id="${list.goodsid}" class="update_content_true" >确定</div>
				</td>
			</tr>
		</c:forEach>

	</table>
	</div>
	<!-- 页码 -->
	<div style="width:650px;margin-left:350px; font-size: 15px; margin-top:15px;">
			第&nbsp;${pb.pc}&nbsp;页&nbsp;共&nbsp;${pb.tp}&nbsp;页
		<c:if test="${pb.pc > 1 }">
			 <a target="1" class="page" id="tpage">首页</a>
			<a target="${pb.pc-1}" class="page" id="dpage" >上一页</a>
		</c:if>
		<%-- 计算begin、end --%>
		<c:choose>
			<%-- 如果总页数不足5页，那么把所有的页数都显示出来！ --%>
			<c:when test="${pb.tp <= 5 }">
				<c:set var="begin" value="1" />
				<c:set var="end" value="${pb.tp }" />
			</c:when>
			<c:otherwise>
				<%-- 当总页数>10时，通过公式计算出begin和end --%>
				<c:set var="begin" value="${pb.pc-2 }" />
				<c:set var="end" value="${pb.pc+2 }" />
				<%-- 头溢出 --%>
				<c:if test="${begin < 1 }">
					<c:set var="begin" value="1" />
					<c:set var="end" value="15" />
				</c:if>
				<%-- 尾溢出 --%>
				<c:if test="${end > pb.tp }">
					<c:set var="begin" value="${pb.tp -4 }" />
					<c:set var="end" value="${pb.tp }" />
				</c:if>
			</c:otherwise>
		</c:choose>
		<%-- 循环遍历页码列表 --%>
		<c:forEach var="i" begin="${begin }" end="${end }">
			<c:choose>
				<c:when test="${i eq pb.pc }">
					<!--当前页不要超链接  -->
			<span id="ipage">${i}</span>
		</c:when>
				<c:otherwise>
					<a target="${i}" class="page"><span id="apage">${i}</span></a>
				</c:otherwise>
			</c:choose>

		</c:forEach>


		<!-- 首页共页上一页下页尾页 -->

		<c:if test="${pb.pc < pb.tp }">
			<a target="${pb.pc+1}" class="page" id="dpage">下一页</a>
			<a target="${pb.tp}" class="page" id="tpage">尾页</a>
		</c:if>
		
	</div>
	</div>
		
		<script type="text/javascript" src="../js/jquery-3.1.0.js"></script>
	<script type="text/javascript">
    $("tr td input").attr("disabled","disabled");
    $(".update_content_true").hide();
	$(".page").click(function(){
		var pc=$(this).attr("target");
		$.getJSON(
				"../GoodsServlet?method=quaryAllGoods", {
					pc:pc
				},
				function(data) {
					if(data=="0")
						$("#rightdiv").load("../yf/goodslist.jsp"); 
					});
	});
	$(".info_content").each(function(){
		 $(this).click(function(){
		 var userid= $(this).parent().parent().find(".info_content").attr("id");
		 alert(userid);
			$.getJSON("../GoodsServlet?method=queryOneGoods&goodsid="+userid,{},function(data){
				if (data == "0")
					$("#rightdiv").load("../yf/goodsinfo.jsp");
			})
		 })
	})
	
	$(".update_content").each(function () {
		$(this).click(function(){
		    $(this).parent().parent().find("input").removeAttr("disabled");
		    $(this).parent().parent().find("input").css("background-color","#000");
		    $(this).parent().parent().find("input").css("color","#fff");
		    $(this).parent().parent().find(".update_content").hide();
			$(this).parent().parent().find(".update_content_true").show();
			$(this).parent().parent().find("td #isnew").click(function(){
				if ($(this).attr("src")=="../img/yes.gif") {
					$(this).attr("src","../img/err.gif");
				}else{
					$(this).attr("src","../img/yes.gif");
				} 
				var isnew=$(this).parent().parent().find("td #isnew").attr("src");
			})
			$(this).parent().parent().find("td #ishot").click(function(){
				if ($(this).attr("src")=="../img/yes.gif") {
					$(this).attr("src","../img/err.gif");
				}else{
					$(this).attr("src","../img/yes.gif");
				} 
				var ishot=$(this).parent().parent().find("td #ishot").attr("src");
			})
			$(this).parent().parent().find("td #isdelete").click(function(){
				if ($(this).attr("src")=="../img/yes.gif") {
					var x=confirm("真的删除吗?");
					if (x) {
						$(this).attr("src","../img/err.gif");
						alert($(this).val());
						$.getJSON("../GoodsServlet?method=deleteOneGoods&goodsid="+$(this).val(),{},function(data){
						 if (data=="0") {
						/* alert("删除成功"); */
						$(this).hide();
						$("#rightdiv").load("../yf/goodslist.jsp");
						} else {
							/* alert("删除失败") ;  */
						}
						})
					}else {
						$(this).attr("src","../img/yes.gif");
					}
				}else{
					$(this).attr("src","../img/yes.gif");
				} 
				var isdelete=$(this).parent().parent().find("td #isdelete").attr("src");
			})

			$(this).parent().parent().find(".update_content_true").click(function(){
			var up=$(this).parent().parent().find(".update_content").attr("id");
					var goodsid=$(this).parent().parent().find("td .goodsid").val();
					var goodssn=$(this).parent().parent().find("td .goodssn").val();
					var goodssn=$(this).parent().parent().find("td .goodssn").val();
					var goodsname=$(this).parent().parent().find("td .goodsname").val();
					var marketprice=$(this).parent().parent().find("td .marketprice").val();
					var goodsnumber=$(this).parent().parent().find("td .goodsnumber").val();
					var isnew=$(this).parent().parent().find("td .isnew").val();
					var ishot=$(this).parent().parent().find("td .ishot").val();
					var giveintegral=$(this).parent().parent().find("td .giveintegral").val();
					if (marketprice>=0) {
						var flag=confirm("真的要修改吗?");
						if (flag) {
					$.getJSON("../GoodsServlet?method=updateAllGoods",{
						goodsid:goodsid,
						goodssn:goodssn,
						goodsname:goodsname,
						marketprice:marketprice,
						goodsnumber:goodsnumber,
						isnew:isnew,
						ishot:ishot,
						giveintegral:giveintegral		
					},function(date){
						 alert("修改成功!");
						 $("input").css("background-color","");
						 $("input").css("color","");
						 $(".update_content").show();
						 $(".update_content_true").hide();
						 $("tr td input").attr("disabled","disabled");
					})
						}else {
							$("tr td input").attr("disabled","disabled");
						}
					}else{
						alert("请输入大于0的数字");
					}
					
					
				})
		
	}) 
	})

	$(".delete_content_true").click(function(){
			var va_id=$(".delete_content_true").attr("id");
			
			alert(va_id);
			$.getJSON("../GoodsServlet?method=deleteOneGoods&id="+va_id,{},
					function(data){
				  alert("删除成功");
			})

		
	})

	$("#select").click(function(){
		var goodsid=$("#goodsid").val();
		var goodsname=$("#goodsname").val();
		$.getJSON("../GoodsServlet?method=findAllGoods",{
			pc:1,
			gid:goodsid,
			gname:goodsname
		},function(data){
			if(data=="0")
				$("#rightdiv").load("../yf/goodslist.jsp"); 
		})
	})
	</script>
	
</body>
</html>